Skip to content

Conversation

@swamirishi
Copy link
Contributor

@swamirishi swamirishi commented Dec 24, 2025

What changes were proposed in this pull request?

Completely get rid of byte array operations for PUT and DELETE from RDBBatchOperation. A direct byte buffer copy can be still performed even if a byte array is sent from the table interface. Since the underlying rocksdb interface is going to perform the same buffer copy on the JNI side i.e. copying heap to off heap memory. Thus it would be more optimal to just copy it to direct byte buffer and get rid of the byte array for gc. This directByteBuffer can be now used for ByteWise comparisons which would be much faster on the native side done in HDDS-14238

P.S. this cannot be done for delete range yet as there is no direct byte buffer api in rocksdb yet. This tries to address the issue
facebook/rocksdb#14197
Once this patch gets merged we can do the same for delete range as well and get rid of the byte array usage from all rocksdb write operations.

What is the link to the Apache JIRA

https://issues.apache.org/jira/browse/HDDS-14166

How was this patch tested?

Added unit tests

@swamirishi swamirishi requested a review from szetszwo December 24, 2025 14:16
@swamirishi swamirishi changed the title Hdds 14166 alt HDDS-14166 Completely get rid of byte array operations from RDBBatchOperation Dec 24, 2025
@swamirishi swamirishi changed the title HDDS-14166 Completely get rid of byte array operations from RDBBatchOperation HDDS-14166. Completely get rid of byte array operations from RDBBatchOperation Dec 24, 2025
@swamirishi swamirishi force-pushed the HDDS-14166_Alt branch 5 times, most recently from a72ab51 to ee1dad3 Compare December 25, 2025 05:47
…Operation

Change-Id: I4a7c62d8cc91173a1374ba5f3515f3c9ac99376f
@swamirishi
Copy link
Contributor Author

Copy link
Contributor

@szetszwo szetszwo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@swamirishi , the cleanup looks great!

We could cleanup more. Please see the comments inlined and also https://issues.apache.org/jira/secure/attachment/13080040/9552_review.patch

*/
private static final class DeleteOp extends Op {
private final byte[] key;
private final CodecBuffer key;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DeleteOp.key is the same as Op.keyBytes. We should move DeleteOp.key to Op, instead of adding it for all the subclasses. (Since there were byte[] and CodecBuffer, I did not mention this previously.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't hold true for delete range. Key would be null in that case

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For for delete range, just use key as startKey.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

private static final class DeleteOp extends Op {
private final byte[] key;
private final CodecBuffer key;
private final AtomicBoolean closed = new AtomicBoolean(false);
Copy link
Contributor

@szetszwo szetszwo Dec 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to key, we should move closed to Op.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We dont need this closed for closing rocksObject since that is already idempotent.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But we need to for CodecBuffer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DeleteRange doesn't have a ByteBuffer API yet. We would still have to depend on the byte array. That is why I don't like the idea of bringing in the codecBuffer Key into Op class
I have raised one
facebook/rocksdb#14197

@swamirishi
Copy link
Contributor Author

@szetszwo i saw you are suggesting to remove DirectByteBuffer check altogether and remove support for heap codec buffer. Things might fail in case someone passes heap byte buffer

@szetszwo
Copy link
Contributor

... Things might fail in case someone passes heap byte buffer

Then, just let it fail.

Change-Id: I3f04b45f0664f7b405d63151354ef8d25930c8bb
@swamirishi
Copy link
Contributor Author

@szetszwo I have modified your patch a bit and addressed most of your concerns lmk if this looks good now


private Op(CodecBuffer keyBuffer) {
this.keyBuffer = keyBuffer;
this.keyBytes = keyBuffer == null ? null : Bytes.newBytes(keyBuffer);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am allowing null so that deleteRange can do things independently

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am still keeping the Bytes.newBytes() since we still need to support byte array operations for delete range

@swamirishi swamirishi requested a review from szetszwo December 30, 2025 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants